// hyb_yl/my/my.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {

    zhiwuss: [], //新增
    //新增
    zhiwu: [],
    userInfo: {},
    qhtab: ["个人", "专家"],
    current: 0,
    touxiang: true,
    touxiangurl: "",
    hide: false,
    imgs: [],
    zhuce: 1,
    array1: [], //科室
    indexx: null,
    array: [], //科室
    yiyuan: [],
    zhuanjiaImg: "", //专家头像
    radioIndex: 1,
    ids: [],
    index: null,
    zhiwuindex: null, //新增
    upload_picture_list: [],
    date: "",
    uplogo: '',
    ge: 0,
    // 导航
    nav: {
      // nav_title
      nav_list: [{
        img: "https://6a69-jin5201-a4503e-1257013711.tcb.qcloud.la/myImg/my_make.png?sign=b6f5d5254b84f593d64b46071d770214&t=1576565533",
          con: "我的预约",
          btn: "yuyueClick"
        }, {
          img: "https://6a69-jin5201-a4503e-1257013711.tcb.qcloud.la/myImg/mycourse.png?sign=d053be4e8d78d13e12de18cb30ae609e&t=1576565559",
          con: "我的课程",
          btn: "dingdanClick"
        }, {
          img: "https://6a69-jin5201-a4503e-1257013711.tcb.qcloud.la/myImg/myxiao.png?sign=2392a1bcb121407f8dc5e92f74d69ea7&t=1576565587",
          con: "我的消费",
          btn: "xiaofeiClick"
        }, {
          img: "https://6a69-jin5201-a4503e-1257013711.tcb.qcloud.la/myImg/record.png?sign=0b9d93ee0a76d4e415a3b90cfd56e0fd&t=1576565657",
          con: "处方记录",
          btn: "Mykchufang"
        }, {
          img: "https://6a69-jin5201-a4503e-1257013711.tcb.qcloud.la/myImg/share.png?sign=ad8ccdfb97bccf0f0071a7c359dda027&t=1576565679",
          con: "我的分享",
          btn: "fenxiangdongtai"
        }, {
          img: "https://6a69-jin5201-a4503e-1257013711.tcb.qcloud.la/myImg/inquiry.png?sign=62ee36452bace46775b5c64d20ecdb5b&t=1576565813",
          con: "图文问诊",
          btn: "wodeWenzhen"
        }, {
          img: "https://6a69-jin5201-a4503e-1257013711.tcb.qcloud.la/myImg/myOrder.png?sign=c0477c314a224e2a27c665e433e24e7d&t=1576565722",
          con: "商品订单",
          btn: "wodeDingd"
        },
        {
          img: "https://6a69-jin5201-a4503e-1257013711.tcb.qcloud.la/myImg/myOrder.png?sign=c0477c314a224e2a27c665e433e24e7d&t=1576565722",
          con: "解读订单",
          btn: "wodejiedu"
        },
      ],
      currentTab: 0
    },

    nav1: {
      // nav_title
      nav_list: [{
        img: "https://lg-o8nytxik-1257013711.cos.ap-shanghai.myqcloud.com/yuyue.png",
        con: "患者预约",
        btn: "huanClick"
      }, {
        img: "https://lg-o8nytxik-1257013711.cos.ap-shanghai.myqcloud.com/dingdan.png",
        con: "我的处方",
        btn: "chufang"
      }, {
        img: "https://lg-o8nytxik-1257013711.cos.ap-shanghai.myqcloud.com/tiwen.png",
        con: "我的回答",
        btn: "daClick"
      }],
      currentTab: 0
    },
    //档案
    danganArr: [123],
    //我的患者
    gongjuArr: [


      {
        img: "https://6a69-jin5201-a4503e-1257013711.tcb.qcloud.la/myImg/speciall.png?sign=31ad9d8464fdc40dd8cd7def044a0392&t=1576566250",
        con: "专家后台",
        btn: "zhuanjiahoutai"
      },
      {
        img: "https://6a69-jin5201-a4503e-1257013711.tcb.qcloud.la/myImg/signrecord.png?sign=07c7cdf9377c38e4c872574cb8e844a1&t=1576566282",
        con: "签约记录",
        btn: "qianyuejilu"
      },
      {
        img: "https://6a69-jin5201-a4503e-1257013711.tcb.qcloud.la/myImg/quiry.png?sign=0f2d3637f5f473a6562f95380a6351a3&t=1576566293",
        con: "快速问诊",
        btn: "kefu"
      },
      {
        img: "https://6a69-jin5201-a4503e-1257013711.tcb.qcloud.la/myImg/inquiryorder.png?sign=ad7e8333b5d99ec96056c8878fc50612&t=1576566325",
        con: "问诊订单",
        btn: "fuwuorder"
      },
    ],
    gongjuArrs: [{
      img: "https://6a69-jin5201-a4503e-1257013711.tcb.qcloud.la/myImg/healthRecord.png?sign=3fd5ba3e3e7b82c6e6f60d5e3dbf99ca&t=1576566462",
        con: "健康档案",
        btn: "huanListClick"
      },
      {
        img: "https://6a69-jin5201-a4503e-1257013711.tcb.qcloud.la/myImg/medical.png?sign=0888e8f4efdfd5fc9a84aea903a93c31&t=1576566501",
        con: "我的报告",
        btn: "tijiabnbaogao"
      },
      {
        img: "https://6a69-jin5201-a4503e-1257013711.tcb.qcloud.la/myImg/myOrder.png?sign=c0477c314a224e2a27c665e433e24e7d&t=1576565722",
        con: "体检订单",
        btn: "tijiandingdan"
      },
    ],
    gongjuArr2: [
      // {
      //   img: "https://lg-o8nytxik-1257013711.cos.ap-shanghai.myqcloud.com/tcdd.png",
      //   con: "档案授权",
      //   btn: "danganshouquan"
      // }, 

      {
        img: "https://6a69-jin5201-a4503e-1257013711.tcb.qcloud.la/myImg/editor.png?sign=8a0a3536a657a1ea8218c3aae6bebd47&t=1576566428",
        con: "编辑资料",
        btn: "dataClick"
      },
      {
        img: "https://6a69-jin5201-a4503e-1257013711.tcb.qcloud.la/myImg/bindphone.png?sign=7567acce8466536e81fc59c5afad8d57&t=1576566397",
        con: "绑定手机",
        btn: "phoneClick"
      },
      {
        img: "https://6a69-jin5201-a4503e-1257013711.tcb.qcloud.la/myImg/yh.png?sign=c25e6ed0454e06d7c674be26f6550696&t=1576575079",
        con: "优惠券",
        btn: "youhuiquan"
      },
      {
        img: "https://6a69-jin5201-a4503e-1257013711.tcb.qcloud.la/myImg/yh.png?sign=c25e6ed0454e06d7c674be26f6550696&t=1576575079",
        con: "年卡",
        btn: "yearcardbtn"
      },
      // {
      //   img: "https://lg-o8nytxik-1257013711.cos.ap-shanghai.myqcloud.com/2.9.png",
      //   con: "我的签约",
      //   btn: "guanClick"
      // },


    ],
    gongjuArr1: [{
        img: "https://lg-o8nytxik-1257013711.cos.ap-shanghai.myqcloud.com/2.11.png",
        con: "编辑资料",
        btn: "zhuanDataClick"
      },
      {
        img: "https://lg-o8nytxik-1257013711.cos.ap-shanghai.myqcloud.com/1.5.png",
        con: "问题金额设置",
        btn: "zhuanWenClick"
      },
      {
        img: "https://lg-o8nytxik-1257013711.cos.ap-shanghai.myqcloud.com/2.9.png",
        con: "扫码核销",
        btn: "erClick"
      },
      {
        img: "https://lg-o8nytxik-1257013711.cos.ap-shanghai.myqcloud.com/2.2.png",
        con: "我的聊天",
        btn: "liaoClick"
      },
      {
        img: "https://lg-o8nytxik-1257013711.cos.ap-shanghai.myqcloud.com/2.9.png",
        con: "我的患者",
        btn: "huanDetailClick"
      },

    ],
    // 底部数据

  },
  wodeWenzhen() {
    wx.navigateTo({
      url: "/hyb_yl/mysubpages/pages/wodezixun/wodezixun"
    });
  },
  wodeDingd: function(e) {
    console.log(e)
    wx.navigateTo({
      url: '/hyb_yl/userCommunicate/pages/order/order',
    })

  },
  zhuanjiahoutai() {
    wx.reLaunch({
      url: "/hyb_yl/mysubpages/pages/backstageIndex/backstageIndex"
    });
  },
  fenxiangdongtai() {
    wx.navigateTo({
      url: '/hyb_yl/mysubpages/pages/myTidings/myTidings',
    })
  },
  youhuiquan() {
    wx.navigateTo({
      url: '/hyb_yl/mysubpages/pages/coupon/coupon',
    })
  },
  //年卡
  yearcardbtn(){
    wx.navigateTo({
      url: '/hyb_yl/backstageServices/pages/yearcardlist/yearcardlist',
    })
  },
  danganshouquan() {
    wx.navigateTo({
      url: '/hyb_yl/mysubpages/pages/warranty/warranty?my_id=' + this.data.my_id,
    })
  },
  qianyuejilu() {
    wx.navigateTo({
      url: '/hyb_yl/userCommunicate/pages/recordSigning/recordSigning',
    })
  },
  fuwuorder: function(e) {
    var that = this
    wx.navigateTo({
      url: '/hyb_yl/mysubpages/pages/my_dingdan1/my_dingdan1',
    })
  },
  jiankangdangan: function(e) {
    var that = this
    var openid = that.data.openid
    wx.navigateTo({
      url: '/hyb_yl/mysubpages/pages/mingxi/mingxi?openid=' + openid,
    })
  },
  tijiabnbaogao: function() {
    var that = this
    var openid = that.data.openid
    wx.navigateTo({
      url: '/hyb_yl/mysubpages/pages/report/report?openid=' + openid,
    })
  },
  xiaofeiClick: function() {
    var that = this
    var openid = that.data.openid
    wx.navigateTo({
      url: '/hyb_yl/mysubpages/pages/mingxi/mingxi?openid=' + openid,
    })
  },
  tiwenClick: function() {
    var that = this
    var openid = that.data.openid
    wx.navigateTo({
      url: '/hyb_yl/mysubpages/pages/wodetiwen/wodetiwen?openid=' + openid,
    })
  },
  dingdanClick: function() {
    wx.navigateTo({
      url: '/hyb_yl/mysubpages/pages/wodedingdan/wodedingdan',
    })
  },
  yuyueClick: function() {
    wx.navigateTo({
      url: '/hyb_yl/mysubpages/pages/wodeyuyue/wodeyuyue',
    })
  },
  // 解读订单
  wodejiedu:function(){
    wx.navigateTo({
      url: '/hyb_yl/mysubpages/pages/unscramble/unscramble',
    })
  },
  tijiandingdan:function(){
    wx.navigateTo({
      url: '/hyb_yl/mysubpages/pages/physicalOrder/physicalOrder',
    })
  },
  // tibaoClick: function () {
  //   wx.navigateTo({
  //     url: '/hyb_yl/jianybaogao/jianybaogao',
  //   })
  // },
  phoneClick: function() {
    wx.navigateTo({
      url: '/hyb_yl/mysubpages/pages/tel/tel',
    })
  },
  dataClick: function() {
    wx.navigateTo({
      url: '/hyb_yl/mysubpages/pages/gerenxinxi/gerenxinxi',
    })
  },
  guanClick: function() {
    wx.navigateTo({
      url: '/hyb_yl/mysubpages/pages/wodeguanzhu/wodeguanzhu',
    })
  },
  huanListClick: function() {
    wx.navigateTo({
      url: '/hyb_yl/zhuanjiasubpages/pages/huanzhexinxi/huanzhexinxi?myinfo=open',
    })
  },
  kefu: function() {
    var that = this
    var ifkefu = that.data.ifkefu
    if (ifkefu == 0) {
      wx.showToast({
        title: '您暂无客服权限',
        icon: 'none'
      })
    } else {
      wx.navigateTo({
        url: '/hyb_yl/tabBar/kefuduihua/kefuduihua',
      })
    }

  },
  //个人 专家

  //提现se
  tiClick: function(e) {
    var that = this
    var docmoney = e.currentTarget.dataset.docmoney
    var myzhuan = that.data.myzhuan
    wx.navigateTo({
      url: '/hyb_yl/twosubpages/pages/my_ti/my_ti?docmoney=' + docmoney + '&zid=' + myzhuan.zid,
    })
  },
  //总收益
  zongClick: function(e) {
    var that = this
    var docmoney = e.currentTarget.dataset.docmoney
    var z_name = e.currentTarget.dataset.z_name
    var zid = that.data.myzhuan.zid
    //查询收益明细

  },
  //职务选择
  zhiwu: function(e) {
    var that = this
    var dex = e.detail.value;
    var pid = that.data.pid;
    var id = pid[dex];
    //console.log(id)
    that.setData({
      pid: id,
      zhiwuindex: e.detail.value
    })
  },
  //关注我的
  huanDetailClick: function() {
    var that = this
    var myzhuan = that.data.myzhuan
    wx.navigateTo({
      url: '/hyb_yl/twosubpages/pages/huan_detail/huan_detail?id=' + myzhuan.zid,
    })
  },

  tijianbaogao: function() {
    wx.showToast({
      title: '功能暂未开发',
    })
  },

  deletetouxiang: function() {
    this.setData({
      touxiang: true,
      touxiangurl: ""
    })
  },
  touxiang: function() {
    var that = this;
    var uniacid = app.siteInfo.uniacid;
    var imgss = that.data.imgs;
    wx.chooseImage({
      count: 1, // 默认9
      sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
      sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有
      success: function(res) {
        // console.log(res)
        // 返回选定照片的本地文件路径列表，tempFilePath可以作为img标签的src属性显示图片
        var tempFilePaths = res.tempFilePaths[0];
        //console.log(tempFilePaths);
        wx.uploadFile({
          url: that.data.url + 'app/index.php?i=' + uniacid + '&c=entry&a=wxapp&do=Uploadsarray&m=hyb_yl',
          filePath: tempFilePaths,
          name: 'upfile',
          formData: {},
          success: function(res) {
            console.log(res.data)
            that.setData({
              uplogo: res.data,
              touxiangurl: tempFilePaths,
              touxiang: false
            })
          },
          fail: function(res) {
            console.log(res)
          },
        })
        that.setData({
          logo: tempFilePaths
        })
      }
    })
  },
  bindDateChange: function(e) {
    this.setData({
      date: e.detail.value
    })
  },
  deleteimg: function(e) {
    var i = e.currentTarget.dataset.index;
    var imgs = this.data.upload_picture_list;
    imgs.splice(i, 1);
    this.setData({
      upload_picture_list: imgs,
      hide: false
    })
  },

  qhtab: function(e) {
    // var that = this
    // var openid = wx.getStorageSync('openid');
    // var zj = that.data.zj
    // app.util.request({
    //   'url': 'entry/wxapp/Zhuanjsh',
    //   data: {
    //     openid: openid
    //   },
    //   success: function (res) {
    //     var types = res.data.data.z_yy_sheng
    //     if (types == 0) {
    //       that.setData({
    //         ge: 0,
    //         types: types,
    //         zj: zj
    //       })
    //       wx.showToast({
    //         title: '资料审核中',
    //       })
    //       return false;
    //     } else {
    //       that.setData({
    //         ge: e.target.dataset.ge,
    //         types: types,
    //         zj: zj
    //       })
    //     }
    //   }
    // })
  },
  uploadImage: function() {
    let that = this;
    var imgss = that.data.imgs;
    wx.chooseImage({
      count: 3,
      sizeType: ["original", "compressed"],
      sourceType: ["album", "camera"],
      success: function(res) {
        imgss.push(res.tempFilePaths);
        that.setData({
          imgs: imgss
        })
        if (imgss.length == 3) {
          that.setData({
            hide: true
          })
        }
      },
    })
  },
  formsubmit1: function(e) {
    var that = this
    var id = that.data.id;
    var openid = wx.getStorageSync('openid');
    var values = e.detail.value
    var z_name = values.z_name
    var z_sex = values.z_sex
    var z_telephone = values.z_telephone
    var z_yiyuan = values.z_yiyuan
    var z_zhiwu = values.z_zhiwu
    var z_content = values.z_content
    var uplogo = that.data.uplogo;
    var pid = that.data.pid
    var that = this;
    var values = e.detail.value;
    app.util.request({
      url: 'entry/wxapp/zhuanjiash',
      data: {
        openid: openid,
      },
      header: {
        'Content-Type': 'application/json'
      },
      success: function(res) {
        var dataimg = res.data
        var arr = dataimg.substring(0, dataimg.length - 1);
        app.util.request({
          url: 'entry/wxapp/Zimages',
          data: {
            id: id,
            z_name: z_name,
            z_sex: z_sex,
            z_telephone: z_telephone,
            z_yiyuan: z_yiyuan,
            z_zhiwu: z_zhiwu,
            z_content: z_content,
            openid: openid,
            dataimg: arr,
            z_thumbs: uplogo,
            pid: pid //分类科室ID
          },
          header: {
            'Content-Type': 'application/json'
          },
          success: function(res) {
            console.log(res)
            wx.showLoading({
              title: "提交成功待审核",
            })
            setTimeout(function() {
              wx.hideLoading();
              wx.reLaunch({
                url: '/hyb_yl/tabBar/index/index',
              })
            }, 800)
          },
          fail: function(err) {
            console.log(err);
          }
        })

      },
      fail: function(err) {
        console.log(err);
      }
    })
    // if (e.detail.value.z_name.length == 0 || e.detail.value.z_telephone.length == 0) {
    //   console.log('1')
    //   wx.showModal({
    //     content: '姓名和手机号不能为空',
    //   })
    // } else if (e.detail.value.z_yiyuan.length == 0) {
    //   console.log('2')
    //   wx.showModal({
    //     content: '请填写所在医院',
    //   })
    // } else if (e.detail.value.pid.length == 0) {
    //   console.log('3')
    //   wx.showModal({
    //     content: '请选择二级科室',
    //   })
    // } else {

    // }

  },
  // uploadImage: function () {
  //   let that = this;
  //   var imgss = that.data.imgs;
  //   wx.chooseImage({
  //     count: 6,
  //     sizeType: ["original", "compressed"],
  //     sourceType: ["album", "camera"],
  //     success: function (res) {
  //       imgss.push(res.tempFilePaths);
  //       that.setData({
  //         imgs: imgss
  //       })
  //       if (imgss.length == 3) {
  //         that.setData({
  //           hide: true
  //         })
  //       }
  //     },
  //   })
  // },
  huanClick: function(e) {
    // var that = this
    // console.log(e)
    // var myzhuan = that.data.myzhuan
    // var form_id = e.detail.formId
    // var openid = wx.getStorageSync('openid')
    // app.util.request({
    //   'url': 'entry/wxapp/UserFormId',
    //   'data': {
    //     form_id: form_id,
    //     openid: openid
    //   },
    //   success: function (res) {
    //     console.log(res)
    //     wx.navigateTo({
    //       url: '/hyb_yl/userLife/pages/huanzheyuyue/huanzheyuyue?id=' + myzhuan.zid,
    //     })
    //   }
    // })
  },
  likesClick(e) {
    console.log(e)
    var openid = wx.getStorageSync('openid')
    if (openid) {
      this.setData({
        isAuthor: true
      })
    } else {
      this.setData({
        isAuthor: false
      })
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var bgc = wx.getStorageSync('color')
    var openid = wx.getStorageSync('openid')
    if (openid) {
      this.setData({
        isAuthor: true
      })
    } else {
      this.setData({
        isAuthor: false
      })
    }
    wx.setNavigationBarColor({
      frontColor: "#ffffff",
      backgroundColor: bgc,
    })
    var that = this;
    that.setData({
      backgroundColor: bgc,
    })
    // var openid = wx.getStorageSync('openid');
    // app.util.request({
    //   'url': 'entry/wxapp/Myphone',
    //   data: {
    //     openid: openid
    //   },
    //   success: function (res) {
    //     //console.log(res)
    //     that.setData({
    //       myphone: res.data.data.u_phone,
    //     })
    //   },
    //   fail: function (err) {
    //     console.log(err)
    //   },
    // })
    // app.util.request({
    //   'url': 'entry/wxapp/Ifent',
    //   success: function (res) {
    //     //console.log(res)
    //     that.setData({
    //       kaiguan: res.data.data.kaiguan,
    //     })
    //   },
    //   fail: function (err) {
    //     console.log(err)
    //   }
    // })


    // var uniacid = app.siteInfo.uniacid;
    // app.util.request({
    //   'url': 'entry/wxapp/url',
    //   'cachetime': '0',
    //   success: function (res) {
    //     //console.log(res)
    //     that.setData({
    //       url: res.data
    //     })
    //   },
    // })
    // app.util.request({
    //   'url': 'entry/wxapp/Scurl',
    //   'cachetime': '0',
    //   success: function (res) {
    //     //console.log(res)
    //     that.setData({
    //       scurl: res.data.data
    //     })
    //   },
    // })
    // var openid = wx.getStorageSync('openid');
    // app.util.request({
    //   'url': 'entry/wxapp/Myzhuan',
    //   data: {
    //     openid: openid
    //   },
    //   success: function (res) {
    //     //console.log(res)
    //     that.setData({
    //       myzhuan: res.data.data,
    //       zhuanjiaImg: res.data.data.z_thumbs
    //     })
    //   },
    //   fail: function (err) {
    //     console.log(err)
    //   },

    // })
    // app.util.request({
    //   'url': 'entry/wxapp/Myinforsarray',
    //   data: {
    //     openid: wx.getStorageSync('openid')
    //   },
    //   success: function (res) {
    //     // console.log(res)
    //     that.setData({
    //       my_id: res.data.data.my_id
    //     })
    //     that.getMyswitch1Change(res.data.data.my_id)
    //   }
    // })
    // var openid = wx.getStorageSync('openid');
    // app.util.request({
    //   'url': 'entry/wxapp/Doctormoney',
    //   data: {
    //     openid: openid
    //   },
    //   success: function (res) {
    //     // console.log(res)
    //     that.setData({
    //       zhuanmoney: res.data.data.overmoney,
    //       num: res.data.data.d_txmoney
    //     })
    //   },
    //   fail: function (err) {
    //     console.log(err)
    //   },

    // })
    // app.util.request({
    //   'url': 'entry/wxapp/Doctormoneytx',
    //   data: {
    //     openid: openid
    //   },
    //   success: function (res) {
    //     //console.log(res.data.data)
    //     that.setData({
    //       zhuanmoneysy: res.data.data.money
    //     })
    //   },
    //   fail: function (err) {
    //     console.log(err)
    //   },

    // })

    // //我的消费总额
    // app.util.request({
    //   'url': 'entry/wxapp/Myxiaofeisum',
    //   data: {
    //     openid: openid
    //   },
    //   success: function (res) {
    //     //console.log(res.data.data)
    //     that.setData({
    //       myxiaofeisum: res.data.data
    //     })
    //   },
    //   fail: function (err) {
    //     console.log(err)
    //   },

    // })

  },
  // 专家更换头像
  // replace:function(){
  //   let that = this;
  //   let zhuanjiaImg = that.data.zhuanjiaImg;
  //   wx.chooseImage({
  //     count:1,
  //     sizeType:["original","cpmpressed"],
  //     sourceType:["album","camra"],
  //     success: function(res) {
  //       let imgUrl = res.tempFilePaths[0];//专家更换头像URL
  //       that.setData({
  //         zhuanjiaImg: imgUrl
  //       })
  //     },
  //   })
  // },
  replace: function() {
    var that = this;
    var uniacid = app.siteInfo.uniacid;
    var zhuanjiaImg = that.data.zhuanjiaImg;
    var openid = wx.getStorageSync('openid')
    wx.chooseImage({
      count: 1, // 默认9
      sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
      sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有
      success: function(res) {
        // console.log(res)
        // 返回选定照片的本地文件路径列表，tempFilePath可以作为img标签的src属性显示图片
        var imgUrl = res.tempFilePaths[0];
        //console.log(tempFilePaths);
        wx.uploadFile({
          url: that.data.url + 'app/index.php?i=' + uniacid + '&c=entry&a=wxapp&do=Uploadsarray&m=hyb_yl',
          filePath: imgUrl,
          name: 'upfile',
          formData: {
            'path': 'wxchat'
          },
          success: function(res) {
            //console.log(res.data)
            that.setData({
              uplogo: res.data,
              zhuanjiaImg: imgUrl
            })
            app.util.request({
              'url': 'entry/wxapp/Myzhuanjiaimg',
              data: {
                openid: openid,
                uplogo: res.data
              },
              success: function(res) {
                console.log(res.data.data)
                that.setData({
                  myxiaofeisum: res.data.data
                })
              },
              fail: function(err) {
                console.log(err)
              },

            })
          },
          fail: function(res) {
            console.log(res)
          },
        })
        that.setData({
          logo: imgUrl
        })
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {
    // this.getIfdoc()
    // this.getBase();
    // this.getMyifkefu()
    // this.getMyvt();
    // this.getKeshi();
    // this.getMyxfjl();
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {
    var bgc = wx.getStorageSync('color')
    wx.setNavigationBarColor({
      frontColor: "#ffffff",
      backgroundColor: bgc,
    })
    this.getBase();
    this.getMyvt();
    this.getKeshi();
    this.getMyxfjl();
    wx.showNavigationBarLoading();
    setTimeout(function() {
      wx.stopPullDownRefresh();
      wx.hideNavigationBarLoading();
    }, 1000)
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */

  getMyxfjl: function() {
    var that = this;
    var openid = wx.getStorageSync('openid')
    var uniacid = app.siteInfo.uniacid;
    app.util.request({
      'url': 'entry/wxapp/Myxfjl',
      data: {
        openid: openid,
        uniacid: uniacid
      },
      success: function(res) {
        //console.log(res)
        that.setData({
          myxfjl: res.data.data,

        })
      },
      fail: function(err) {
        console.log(err)
      },

    })
  },
  //我的消费
  getMyvt: function() {
    var that = this;
    var openid = wx.getStorageSync('openid')
    //console.log(openid)
    app.util.request({
      'url': 'entry/wxapp/myvt',
      data: {
        openid: openid,
      },
      success: function(res) {
        //console.log(res)
        that.setData({
          myvt: res.data.data,
          openid: openid
        })
      },
      fail: function(err) {
        console.log(err)
      },

    })
  },
  bindPickerChange1: function(e) {
    var that = this;
    var dex = e.detail.value;
    var ids = that.data.keshiid;
    var id = ids[dex];
    console.log(id);
    var arrs = that.data.zhiwu; //新增
    var arr = arrs[dex]; //新增
    app.util.request({
      'url': 'entry/wxapp/Category2',
      data: {
        id: id
      },
      success: function(res) {
        console.log(res)
        that.setData({
          zhiwuss: res.data.data.name,
          pid: res.data.data.id
        })
      },
      fail: function(err) {
        console.log(err)
      },

    })
    that.setData({
      index: e.detail.value,
      id: id,
      zhiwuss: arr //新增
    })
  },
  bindPickerChange2: function(e) {
    var that = this;
    var dex = e.detail.value;
    var monery = that.data.monery;
    var pid = that.data.pid;
    var id = pid[dex];
    console.log(id);
    that.setData({
      indexx: dex,
      monerynum: monery[dex],
      id: id
    })
  },
  bindPickerChange: function(e) {
    this.setData({
      index: e.detail.value
    })
  },
  switchChange: function(e) {
    console.log('switch1 发生 change 事件，携带值为', e.detail.value)
  },
  radio: function(e) {
    //console.log(e)
    var ky_sex = e.detail.value
    this.setData({
      radioIndex: e.detail.value,
      ky_sex: ky_sex
    })
  },
  getBase: function() {
    var that = this;
    // console.log(app);
    app.util.request({
      'url': 'entry/wxapp/Base',
      success: function(res) {
        that.setData({
          baseinfo: res.data.data,
          bq_thumb: res.data.data.bq_thumb,
          bq_name: res.data.data.bq_name
        })
      },
      fail: function(err) {
        console.log(err)
      },

    })

  },
  getKeshi: function() {
    var that = this;
    app.util.request({
      'url': 'entry/wxapp/Keshi',
      success: function(res) {
        that.setData({
          keshi: res.data.data.name,
          keshiid: res.data.data.id
        })
      },
      fail: function(err) {
        console.log(err)
      }
    })
  },
  uploadpic: function(e) {
    var that = this
    var upload_picture_list = that.data.upload_picture_list
    wx.chooseImage({
      count: 3, // 默认9，这里显示一次选择相册的图片数量
      sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
      sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有
      success: function(res) {
        // 返回选定照片的本地文件路径列表，tempFilePath可以作为img标签的src属性显示图片
        var tempFiles = res.tempFiles
        //循环把图片加入上传列表
        for (var i in tempFiles) {
          tempFiles[i]['upload_percent'] = 0
          tempFiles[i]['path_server'] = ''
          upload_picture_list.push(tempFiles[i])
        }
        that.setData({
          upload_picture_list: upload_picture_list,
        })
        if (upload_picture_list.length == 3) {
          that.setData({
            hide: true
          })
        }
        //循环把图片上传到服务器 并显示进度
        for (var j in upload_picture_list) {
          if (upload_picture_list[j]['upload_percent'] == 0) {
            upload_file_server(that, upload_picture_list, j)
          }
        }
      }
    })

    function upload_file_server(that, upload_picture_list, j) {
      var uniacid = app.siteInfo.uniacid;
      // console.log(uniacid);
      var openid = wx.getStorageSync('openid');
      // console.log("开始上传" + j + "图片到服务器：")
      //console.log(upload_picture_list[j])
      var upload_task = wx.uploadFile({
        url: that.data.url + 'app/index.php?i=' + uniacid + '&c=entry&a=wxapp&do=msg_send_imgs&m=hyb_yl', //需要用HTTPS，同时在微信公众平台后台添加服务器地址
        filePath: upload_picture_list[j]['path'], //上传的文件本地地址
        name: 'file',
        formData: {
          'path': 'wxchat',
          openid: openid,
          uniacid: uniacid,
          i_type: 2
        }, //附近数据，这里为路径
        success: function(res) {
          // console.log(res)
          var data = res.data //字符串转化为JSON
          that.setData({
            thumb: data,
            upload_picture_list: upload_picture_list
          })
          // console.log("图片上传" + j + "到服务器完成：")
          //console.log(upload_picture_list[j]['path'])
        }
      })
      upload_task.onProgressUpdate((res) => {
        // console.log('上传进度', res.progress)
        // console.log('已经上传的数据长度', res.totalBytesSent)
        // console.log('预期需要上传的数据总长度', res.totalBytesExpectedToSend)
        upload_picture_list[j]['upload_percent'] = res.progress
        // console.log('第' + j + '个图片上传进度：' + upload_picture_list[j]['upload_percent'])
        //console.log(upload_picture_list)
        that.setData({
          upload_picture_list: upload_picture_list
        })

      })
    }
  },
  toast: function() {
    wx.redirectTo({
      url: '/hyb_yl/tabBar/index/index'
    })
  },
  toast1: function(e) {
    //console.log(e)
    wx.redirectTo({
      url: '/hyb_yl/tabBar/community/community'
    })
  },
  toast2: function() {
    wx.redirectTo({
      url: '/hyb_yl/mysubpages/pages/shop/shop'
    })
  },
  toast3: function() {
    var openid = wx.getStorageSync('openid');
    app.util.request({
      'url': 'entry/wxapp/Myphone',
      data: {
        openid: openid
      },
      success: function(res) {
        app.globalData.myphone = res.data.data
        app.globalData.openid = openid
      },
      fail: function(err) {
        console.log(err)
      },

    })
    setTimeout(function() {
      wx.redirectTo({
        url: '/hyb_yl/tabBar/my/my'
      })
    }, 350)
  },
  toast4() {
    wx.redirectTo({
      url: '/hyb_yl/userLife/pages/jibingyufang/jibingyufang'
    })
  },
  MyJifen() {
    wx.navigateTo({
      url: "/hyb_yl/backstageLifes/pages/integral/integral"
    });
  },
  // 二维码点击事件
  erClick: function() {
    var that = this
    var myxfjl = that.data.myxfjl
    if (myxfjl.u_type == 0) {
      wx.showToast({
        title: '暂无核销权限',
      })
    } else {
      wx.showActionSheet({
        itemList: ['预约核销'],
        success: function(res) {
          if (res.tapIndex == 0) {
            wx.navigateTo({
              url: '/hyb_yl/zhuanjiasubpages/pages/hexiao/hexiao',
            });
          }
        },
        fail: function(res) {
          console.log(res.errMsg)
        }
      })
    }

  },
  chufang: function(e) {
    var that = this
    console.log(e)
    var myzhuan = that.data.myzhuan
    var form_id = e.detail.formId
    var openid = wx.getStorageSync('openid')
    app.util.request({
      'url': 'entry/wxapp/UserFormId',
      'data': {
        form_id: form_id,
        openid: openid
      },
      success: function(res) {
        console.log(res)
        wx.navigateTo({
          url: '/hyb_yl/userLife/pages/my_prescription/my_prescription?id=' + myzhuan.zid,
        })
      }
    })
  },
  daClick: function(e) {
    var that = this
    var myzhuan = that.data.myzhuan
    console.log(myzhuan)
    var form_id = e.detail.formId
    var openid = wx.getStorageSync('openid')
    app.util.request({
      'url': 'entry/wxapp/UserFormId',
      'data': {
        form_id: form_id,
        openid: openid
      },
      success: function(res) {
        console.log(res)
        wx.navigateTo({
          url: '/hyb_yl/userLife/pages/wodehuida/wodehuida?zid=' + myzhuan.zid,
        })
      }
    })
  },
  zhuanDataClick: function() {
    var that = this
    var myzhuan = that.data.myzhuan
    wx.navigateTo({
      url: '/hyb_yl/zhuanjiasubpages/pages/zhuanjiaziliao/zhuanjiaziliao?id=' + myzhuan.zid,
    })
  },
  zhuanWenClick: function() {
    var that = this
    var myzhuan = that.data.myzhuan
    wx.navigateTo({
      url: '/hyb_yl/userLife/pages/wentijine/wentijine?zid=' + myzhuan.zid,
    })
  },
  liaoClick: function() {
    var that = this
    var myzhuan = that.data.myzhuan
    wx.navigateTo({
      url: '/hyb_yl/mysubpages/pages/guanzhuwode/guanzhuwode?zid=' + myzhuan.zid,
    })
  },
  //理赔列表
  lipeiClick: function() {
    wx.navigateTo({
      url: '/hyb_yl/mysubpages/pages/zhuan_huan/zhuan_huan',
    })
  },
  //查看是否提交了资料
  getIfdoc: function() {
    var that = this
    var openid = wx.getStorageSync('openid');
    app.util.request({
      'url': 'entry/wxapp/Zhuanjsh',
      data: {
        openid: openid
      },
      success: function(res) {
        //console.log(res)
        that.setData({
          zhuce: res.data.data.z_yy_sheng,
          id: res.data.data,
          zj: res.data.data
        })
      }
    })
  },
  Mykchufang: function() {
    //查询我的uid
    var that = this
    wx.navigateTo({
      url: '/hyb_yl/mysubpages/pages/my_hzprescription/my_hzprescription',
    })
  },

  kt: function(a) {
    var that = this
    var my_id = that.data.my_id
    if (a.detail.value == false) {
      var mydatype = 0
    }
    if (a.detail.value == true) {
      var mydatype = 1
    }
    app.util.request({
      'url': 'entry/wxapp/Myswitch1Change',
      data: {
        my_id: my_id,
        mydatype: mydatype,
        op: 'post'
      },
      success: function(res) {
        console.log(res)
        a.detail.value ? that.setData({
          flag: 1
        }) : that.setData({
          flag: 0
        });
      }
    })
  },
  getMyswitch1Change: function(my_id) {
    var that = this
    app.util.request({
      'url': 'entry/wxapp/Myswitch1Change',
      data: {
        my_id: my_id,
        op: 'display'
      },
      success: function(res) {
        console.log(res)
        if (res.data.mydatype == 0) {
          that.setData({
            authStateBoo: false
          })
        }
        if (res.data.mydatype == 1) {
          that.setData({
            authStateBoo: true
          })
        }
      }
    })
  },
  //查询我是否是客服
  getMyifkefu: function() {
    var that = this
    var openid = wx.getStorageSync('openid')
    app.util.request({
      'url': 'entry/wxapp/Kfuid',
      success: function(res) {
        console.log(res)
        if (res.data.openid == openid) {
          that.setData({
            ifkefu: 1
          })
        } else {
          that.setData({
            ifkefu: 0
          })
        }
      }
    })
  }
})